<?php
function no_space($str) {
	return preg_replace('/\s+/','_', $str);
}

function error($text,$title='',$code=500) {
	show_error($text,$code,$title);
	log_message('error',$this->input->ip_address()." $title: $text");
	exit();
}

function is_image($filename) {
	return substr(get_mime_by_extension($filename),0,5)=='image';
}

function format_bytes($size) {
    $units = array(' B', ' KB', ' MB', ' GB', ' TB');
    for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
    return round($size, 2).$units[$i];
}

function cat_title($cat,$languages) {
	$title ='';
	foreach ($languages as $language)
		$title.= "[$language->id]: '".$cat->{"name_$language->id"}."' ";
	return $title;
}
